{{extend 'layout.html'}}
<link rel="stylesheet" media="screen,projection" type="text/css" href="{{=URL(request.application,'static/plugin_useradmin','base.css')}}" />
<div class="flash">{{=response.flash or ''}}</div>
<div id="useradmin">
<h1>{{=T('Admin users and groups')}}</h1><br />
<h3>{{=T('Users')}}</h3>
<table id='tuseradmin' >
    <tr>
        <th>{{=T('User')}}</th>
        <th>{{=T('Email')}}</th>
        <th>{{=T('Group')}}</th>
        <th>{{=T('Status')}}</th>
        <th>{{=T('Block')}}</th>
        <th>{{=T('Delete')}}</th>
    </tr>
    {{for user in users:
            status = (IMG(_src=URL(request.application,'static/plugin_useradmin','flag_green.png'), _alt="OK"))
    
        if user.registration_key=="blocked":
            status = XML('Waiting approve: %s'%DIV(IMG(_src=URL(request.application,'static/plugin_useradmin','accept.png'), _alt="Approve User"), _title="Approve User" , _onclick="ajax('%s',[],'useradmin');"%URL(r=request,f='index',vars=dict(approve=user.id))))
            
            status = XML('waiting to approve: %s'% FORM(INPUT(_name='approve', _value=user.id, _type='hidden'),  
            INPUT(_type='image', _src=URL(request.application,'static/plugin_useradmin','accept.png')) ))
        
        elif user.registration_key!="":
            status = 'waiting email confirmation'
        pass
        groups = [x.group_id for x in user.auth_membership.select()]
    }}
    {{=TR(
        TD(user.first_name),
        TD(A(user.email,_href="mailto:%s"%user.email)),
        TD(TABLE([TR(TD(g.role), TD(FORM(INPUT(_name='del_usergroup', _value=user.id, _type='hidden'), 
            INPUT(_name='del_groupuser', _value=g.id, _type='hidden'), 
        INPUT(_type='image', _src=URL(request.application,'static/plugin_useradmin','cancel.png')) )) 
        ) for g in groups]),
        forms_users_groups[user.id] ),
        TD(status),
        TD(FORM(INPUT(_name='block_user', _value=user.id, _type='hidden'), INPUT(_type='image', _src=URL(request.application,'static/plugin_useradmin','stop.png')) )),
        TD(FORM(INPUT(_name='del_user', _value=user.id, _type='hidden'), INPUT(_type='image', _src=URL(request.application,'static/plugin_useradmin','cancel.png')) ))
        )}}
    {{pass}}
</table>
<p>&nbsp;</p>
<table id="guseradmin">
    <tr>
    <th>{{=T('Manage Group')}}</th>
    <th>{{=T('Create a group')}}</th>   
    </tr>
    <tr>
        <td>
            
            {{=TABLE([TR(TD(g.role),TD(FORM(INPUT(_name='edit_group', _value=g.id, _type='hidden'), INPUT(_type='image', _src=URL(request.application,'static/plugin_useradmin','edit.jpg')) )), TD(FORM(INPUT(_name='del_group', _value=g.id, _type='hidden'), INPUT(_type='image', _src=URL(request.application,'static/plugin_useradmin','cancel.png')) )) )  for g in db_groups])}}
        </td>
        <td>
            {{=form_group}}
        </td>
    </tr>
</table>
</div>
